package org.springsource.batch;

import java.util.ArrayList;
import java.util.List;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.social.twitter.api.Tweet;
import org.springframework.stereotype.Component;

/**
 * {@link ItemReader} with hard-coded input data.
 */

@Component("reader")
public class ExampleItemReader implements ItemReader<Tweet> {
	private int index = 0;
	
	private List<Tweet> itemList;

	
	public ExampleItemReader() {
		itemList = new ArrayList<Tweet>();
		itemList.add(new Tweet(0, null, null, null, null, null, 0, null, null));
	}
	
	@Override
	public Tweet read() throws Exception, UnexpectedInputException,
			ParseException {
		System.out.println("size"+itemList.size());
		if (index < itemList.size()) {
			Tweet str = itemList.get(index++);
			System.out.println("Read[ " + index + " ] = " + str);
			return str;
		} else {
			return null;
		}
	}

}
